package com.dongdongshop.controller;

import com.alibaba.fastjson.JSONObject;
import com.dongdongshop.data.Result;
import com.dongdongshop.enums.ResultEnum;
import com.dongdongshop.service.SellerService;
import com.dongdongshop.vo.SellerVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("seller")
public class SellerController {

    @Autowired
    private SellerService sellerService;

    @PostMapping("sellerByName")
    public Result sellerByName(@RequestParam String sellerId){
        SellerVO sellerVO = sellerService.sellerByName(sellerId);
        return Result.OK().setData(sellerVO);
    }

    @PostMapping("sellerAdd")
    public Result sellerAdd(@RequestBody SellerVO sellerVO){
        try{
            sellerService.sellerAdd(sellerVO);
        }catch (Exception e){
            return Result.response(ResultEnum.ADD_NAME_REPEAT);
        }
        return Result.OK();
    }

    @PostMapping("sellerAll")
    public Result sellerAll(){
        List<SellerVO> voList = sellerService.sellerAll();
        return Result.OK().setData(voList);
    }

    @PostMapping("audit")
    public Result audit( String id,int status){
        sellerService.updateStatus(id,status);
        return Result.OK();
    }


}
